//
var year = 2019;
var  mounth = 5;



document.querySelector("#nian").innerHTML = year;
document.querySelector("#yue").innerHTML = mounth;


function runnian(y){
    if (y % 400 === 0 || (y % 4 === 0 && y % 100 !==0)){
        return true;
    }else {
        return false;
    }
}
var days =0;
//计算天数
for (var i=1980; i<year;i++){
    if (runnian(i)){
        days+=366;
    }else {
        days += 365;
    }
}
/*days+=2;*/
console.log(days);


for (var p=0;p<mounth;p++){
    switch (p){
        case 1:
            days+=31;
            break;
        case 2:
            if (runnian(year)){
                days+=29;
            }else {
                days+=28;
            }
            break;
        case 3:
            days+=31;
            break;
        case 4:
            days+=30;
            break;
        case 5:
            days+=31;
            break;
        case 6:
            days+=30;
            break;
        case 7:
            days+=31;
            break;
        case 8:
            days+=31;
            break;
        case 9:
            days+=30;
            break;
        case 10:
            days+=31;
            break;
        case 11:
            days+=30;
            break;
        case 12:
            days+=31;
            break;
    }
}

//在算本月有多少天

//本月天数
var day=0;
switch (mounth){
    case 1:
        day+=31;
        break;
    case 2:
        if (runNian(year)){
            day+=29;
        }else {
            day+=28;
        }
        break;
    case 3:
        day+=31;
        break;
    case 4:
        day+=30;
        break;
    case 5:
        day+=31;
        break;
    case 6:
        day+=30;
        break;
    case 7:
        day+=31;
        break;
    case 8:
        day+=31;
        break;
    case 9:
        day+=30;
        break;
    case 10:
        day+=31;
        break;
    case 11:
        day+=30;
        break;
    case 12:
        day+=31;
        break;
}
console.log(day);

//上个月天数
var prevDay = 0;
if(mounth == 1){
    prevDay += 31;
}else {
    switch (mounth - 1) {
        case 1:
            prevDay += 31;
            break;
        case 2:
            if (runNian(year)) {
                prevDay += 29;
            } else {
                prevDay += 28;
            }
            break;
        case 3:
            prevDay += 31;
            break;
        case 4:
            prevDay += 30;
            break;
        case 5:
            prevDay += 31;
            break;
        case 6:
            prevDay += 30;
            break;
        case 7:
            prevDay += 31;
            break;
        case 8:
            prevDay += 31;
            break;
        case 9:
            prevDay += 30;
            break;
        case 10:
            prevDay += 31;
            break;
        case 11:
            prevDay += 30;
            break;
        case 12:
            prevDay += 31;
            break;
    }
}
console.log(prevDay);

//星期二开始的
days+=2;

//本月1号星期几
var er = days % 7;
console.log(er);
if(er == 0){
    er +=7
}

//当前日历多少天
var num = 42;

//下一个月有多少天

//下一个月有多少天=日历天数-1号星期几-本月多少天
var nst = num - er - day;
console.log(nst);

//取到今天
var thisdate = new Date().getDate();

var date1 = document.querySelector("#date1");

//日历天
//30
for (var y = prevDay- er +1; y<=prevDay;y++){
    date1.innerHTML +="<span class='hh'>" + y +"</span>"
}
for (var a =1;a <= day;a++){
    if ( a ==  thisdate){
        date1.innerHTML +="<span class='tt'>"+a+"</span>"
    }else {
        date1.innerHTML +="<span>"+a+"</span>"
    }
}
for (var o=1;o<=nst;o++){
    date1.innerHTML +="<span class='ii'>"+o+"</span>"
}
